package com.weex.app.extend;

import android.util.Base64;

import com.taobao.weex.annotation.JSMethod;
import com.taobao.weex.bridge.JSCallback;
import com.taobao.weex.common.WXModule;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Hash extends WXModule {

    @JSMethod(uiThread=false)
    public void b64sha256(String input, JSCallback callback) throws NoSuchAlgorithmException, UnsupportedEncodingException {
        MessageDigest digest = MessageDigest.getInstance("SHA-256");

        digest.reset();
        byte[] byteData = digest.digest(input.getBytes("UTF-8"));

        callback.invoke(Base64.encodeToString(byteData, Base64.URL_SAFE | Base64.NO_PADDING | Base64.NO_WRAP));

    }
    
}
